# -*- coding: utf-8 -*-
'''
@author: olivia.dou
Created on: 2023/1/30 13:44
desc: 园区获客页
'''
from appium.webdriver.common.appiumby import AppiumBy
import time
from proj_spec.CLUE.mobile_po.clue_app_base_page import CLUEAppBasePage


class AccuisitByParkPage(CLUEAppBasePage):

    def choose_district(self,district):
        """

        :param district:

        :return:
        """
        self.find_element_and_click(self._district_filter_locator)
        # page_source = self.driver.page_source
        district_trail = district.split('/')
        unscrollable_count = 0  # 记录行政区不可滚动的计数
        # 需打开不可见元素
        # self.driver.update_settings({"allowInvisibleElements": True})
        time.sleep(3)

        for i, text in enumerate(district_trail):
            try:
                self.find_element_and_click((AppiumBy.ANDROID_UIAUTOMATOR,
                                             'new UiScrollable(new UiSelector().scrollable(true).instance(%s)).setAsVerticalList().scrollIntoView(new UiSelector().textContains("%s"));'
                                             % (i + 3 - unscrollable_count, text)))
                # self.find_element_and_click((AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().textContains("%s");' % text))
            except Exception as e:  # unscrollable
                unscrollable_count += 1
                self.find_element_and_click(
                    (AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().textContains("%s")' % text))
            time.sleep(2)

        self.find_element_and_click(self._confirm_btn_locator)
